<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .basic {
            width: 500px;
            height: 300px;
            /* background-color: blue; */
            border-color: black;
            border-width: 10px;
            border-style: solid;
        }
        .happy {
            background-color: orange;
        }
        .sad {
            background-color: darkgray;
        }
        .normal {
            background-color: bisque;
        }
    </style>
</head>
<body>
    <div id="app">
        <!-- 字符串写法，适用于样式的类名不确定 需要动态指定 -->
        <div class="basic" :class="mood" @click="changeMood"></div>
<!-- 绑定样式 数组写法，适用于 要绑定的样式个数不确定 名字也不确定 -->
        <div class="basic" :class="classArr" ></div>
<!-- 绑定样式 对象写法，适用于个数确定 名字确定 但是要动态确定用不用 -->
        <div class="basic" :class="classObj"></div>

    </div>
    <script src="../vuejs/vue.js"></script>
    <script>
        const vm = new Vue({
            el : '#app',
            data() {
                return {
                    mood : '',
                    classArr : [class1,class2],
                    classObj : {
                        class1 : true,
                        class2 : false
                    }
                }
            },
            methods: {
                changeMood(){
                    const arr = ['happy','sad','normal']
                    this.mood = arr[Math.floor(Math.random()*3)]
                }
            },
        })
    </script>
</body>
</html>